<template>
	<view class="page page-fill">
		<view class="search-wraper">
			 <view class="search-icon-wraper">
				  <image class="search-icon" src="../../static/icon/search-icon.png" mode=""></image>
			 </view>
			 <input class="search-input" maxlength="10" type="text"  confirm-type="search" @confirm="searchTrailer" placeholder="搜索预告" />
		</view>
		
		<view class="movie-list">
			 <view class="movie-list-item" :data-trailerId = "item.id" @click = "toMovieDeatil" v-for="(item,index) in trailerList">
			 	<image class="movie-image" :src="item.cover" mode=""></image>
			 </view>

			 
		</view>
			 
	</view>
</template>

<script>
	export default {
		data() {
			return {
				  trailerListQuery:{
					keywords:'',
				    page:1,
					pageSize:0,
					total:0
				},
				trailerList:[]
			}
		},
		onLoad(){
		 this.getTrailerList();
		},
		onReachBottom(){
		     this.trailerListQuery.page +=1; 
			 if(this.trailerListQuery.page >this.trailerListQuery.total) return;
			 
			 this.getPgaeTrailerList(this.trailerListQuery);
		},
		methods: {
			getTrailerList(){
				 uni.showLoading({
				 	mask:true,
					title:"请稍后..."
				 });
			    uni.showNavigationBarLoading();
				uni.request({
					method: 'POST',
					url:this.serverUrl + '/search/list?qq=3316368400&keywords=&page=&pageSize=15',
					success:(res)=>{
						  let data = res.data;
						      if(data.status!=200 ) return;
							   this.trailerList = data.data.rows;
					           this.trailerListQuery.total = data.data.total;
							   console.log(this.trailerList);
							 
							   
					},
					complete:()=>{
						uni.hideLoading();
						uni.hideNavigationBarLoading();
					}
				})
			},
			searchTrailer(e){
			 let value = e.detail.value;
				  this.trailerListQuery.keywords = value;
				   this.trailerList = [];

				 this.getPgaeTrailerList(this.trailerListQuery)
				
			},
			getPgaeTrailerList(query){
				uni.showLoading({
				 	mask:true,
					title:"请稍后..."
				 });
				uni.showNavigationBarLoading();
				uni.request({
					method: 'POST',
					url:this.serverUrl + '/search/list?qq=3316368400&keywords='+query.keywords+'&page='+query.page+'&pageSize='+query.pageSize,
					success:(res)=>{
						 let data = res.data;
						     if(data.status!=200 ) return;
							   this.trailerList = this.trailerList.concat(data.data.rows);
							 
							   
					},
					complete:()=>{
						uni.hideLoading();
						uni.hideNavigationBarLoading();
					}
				})
			},
			toMovieDeatil(e){
				let id = e.currentTarget.dataset.trailerid;
	
			
				uni.navigateTo({
				    url: '../movie/movie?trailerId='+id
				});
			}
		
		}
	}
</script>

<style>
 @import url("search.css");
</style>
